package com.kk.netty.nio.demo;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

import static com.kk.netty.nio.ByteBufferUtil.debugAll;

/**
 * 分散集中读
 */
public class TestScatteringReads {
    public static void main(String[] args) {
        try (RandomAccessFile file = new RandomAccessFile ("boot_netty/helloword/3parts.txt", "rw")) {
            FileChannel channel = file.getChannel ( );
            ByteBuffer a = ByteBuffer.allocate (3);
            ByteBuffer b = ByteBuffer.allocate (3);
            ByteBuffer c = ByteBuffer.allocate (5);
            channel.read (new ByteBuffer[]{a, b, c});
            a.flip ( );
            b.flip ( );
            c.flip ( );
            debugAll (a);
            debugAll (b);
            debugAll (c);
        } catch (IOException e) {
            e.printStackTrace ( );
        }
    }
}
